package com.econ.powercloud.ems.common.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * 挂牌类型枚举
 * @author hcx
 */

public enum ListingTypeEnum implements EnumMethod{

    NORMAL(0,"正常"),
    OVERHAUL(1, "检修");


    private Integer code;
    private String desc;

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }


    ListingTypeEnum(int code, String desc){
        this.code=code;
        this.desc=desc;
    }

    public static ListingTypeEnum parseCode(int code){
        for(ListingTypeEnum type: ListingTypeEnum.values()){
            if(type.getCode() == code){
                return type;
            }
        }
        return NORMAL;
    }

    public static String fromCode(int code){
        for(ListingTypeEnum type: ListingTypeEnum.values()){
            if(type.getCode() == code){
                return type.getDesc();
            }
        }
        return null;
    }

    /**
     * 根据组合值 反推出枚举数组
     * @param combCode
     * @return
     */
    public static List<ListingTypeEnum> fromCombCode(Integer combCode){
        if (combCode == null) {
            return null;
        }
        List<ListingTypeEnum> list = new ArrayList<>();
        for(int i = 0; i < 4; i++){
            if((combCode >> i & 1) == 1){
                ListingTypeEnum listingTypeEnum = parseCode(1 << i);
                list.add(listingTypeEnum);
            }
        }
        return list;
    }
}
